import java.util.Arrays;

/**
 * 189 - 转轮数组
 */
class Solution {
    public void change(int[] nums, int left, int right){
        while(left < right){
            int tmp = nums[left];
            nums[left] = nums[right];
            nums[right] = tmp;
            left++;
            right--;
        }
    }
    public void rotate(int[] nums, int k) {
        while(k > nums.length){
            k = k%nums.length;
        }
        change(nums,0,nums.length - 1);
        change(nums,0,k-1);
        change(nums,k,nums.length - 1);
    }
}
public class Test {
    public static void main1(String[] args) {
        Solution solution = new Solution();
        int[] nums = new int[]{1, 2, 3, 4, 5};
        solution.rotate(nums,2);
        System.out.println(Arrays.toString(nums));
    }

    public static void main(String[] args) {
        Solution3 solution3 = new Solution3();
        String s = " sf d d  ";
        s = s.trim();
        System.out.println(s);
        //solution3.countSegments(s);
    }
}
/**
 * 434 - 字符串中的单词数
 */
class Solution3 {
    public int countSegments(String s) {
        s = s.trim();
        if(s.length() == 0)return 0;
        int count = 1;
        for(int i = 0; i < s.length(); i++){
            if(s.charAt(i) == ' '){
                count++;
            }
        }
        return count;
    }
}
